import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
    {
        name: 'login',
        path: '/',
        component: () => import('@/view/login/login'),
        meta: {
            title: '登录',
        },
    },
    {
        name: 'home',
        path: '/home',
        component: () => import('@/view/home/home'),
        meta: {
            title: '首页'
        }
    },
    {
        name: 'search',
        path: '/search',
        component: () => import('@/view/search/search'),
        meta: {
            title: '搜索'
        }
    },
    {
        name: 'verify',
        path: '/verify',
        component: () => import('@/view/verify/verify'),
        meta: {
            title: '验证'
        }
    },
    {
        name: 'newfriend',
        path: '/newfriend',
        component: () => import('@/view/newfriend/newfriend'),
        meta: {
            title: '新朋友'
        }
    },
    {
        name: 'chatwindow',
        path: '/chatwindow',
        component: () => import('@/view/chatwindow/chatwindow'),
        meta: {
            title: '聊天'
        }
    }
];

const router = createRouter({
    routes,
    history: createWebHashHistory(),
});

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }
    next();
});

export { router };
